package com.atguigu.guli.service.edu.controller.admin;


import com.atguigu.guli.service.base.exception.GuliException;
import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.service.SubjectService;
import com.mysql.cj.log.Log;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-02-13
 */
@Slf4j
@RestController
@RequestMapping("admin/edu/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "Excel批量导入类别数据")
    @PostMapping("import")
    public R batchImport(@ApiParam(value = "Excel文件" , required = true) @RequestParam("file") MultipartFile file){
        try {
            subjectService.batchImport(file.getInputStream());
            return R.ok().message("批量导入成功！");
        } catch (Exception e) {
            log.error(ExceptionUtils.getStackTrace(e));
            return R.error().message("批量导入失败！");
        }
    }

}

